package com.uncp.comisiondeadmision.comprobantedepago.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.uncp.comisiondeadmision.comprobantedepago.beans.AsincronaBean;
import com.uncp.comisiondeadmision.util.MySqlDBConn;



public class MySqlEscuelaDAO implements EscuelaDAO {

	@Override
	public List<AsincronaBean> traerEscuelas(int codFacultad) throws Exception {
		List<AsincronaBean> lista = new ArrayList<AsincronaBean>();
		AsincronaBean bean = null;
		String sql = "SELECT distinct codescuela, nombre FROM  escuela where codfacultad =" + codFacultad;
		System.out.println("SENTENCIA SQL : " + sql);

		Connection conn = null;
		try {
			conn = new MySqlDBConn().getConnection();
			Statement pstm = conn.createStatement();
			ResultSet rst = pstm.executeQuery(sql);
			while (rst.next()) {
				bean = new AsincronaBean();
				bean.setIntCodEscuela(rst.getInt(1));
				bean.setStrDescEscuela(rst.getString(2));
				lista.add(bean);
			}

			rst.close();
			pstm.close();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			conn.close();
		}
		return lista;
	}

}
